/**
 * @class   wosh::interfaces::devices::Switch
 * @brief   Standard interface of a generic Switch (device).
 *
 * @ingroup Interfaces
 ****************************************************************************
 * @version 0.8.384 $Id: Switch.h 2885 2010-08-10 01:12:38Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Interfaces_Devices_Switch_H__
 #define __WOSH_Interfaces_Devices_Switch_H__

 #include <interfaces/Device.h>


namespace wosh {
 namespace interfaces {
  namespace devices {

 #define _Switch_METHOD_on				"on"
 #define _Switch_METHOD_off				"off"


class Switch : public virtual Device
 {
	WOSH_BUNDLE_INTERFACE("wosh::interfaces::devices::Switch")

	public:
		///  states of the switch
		enum SWITCH_STATE {
			STATE_UNKNOWN		= 0x00,	///< state is unknown, (default during initialization)
			STATE_ON			= 0x01,	///< switch is on (100%)
			STATE_ONDIMMED		= 0x03,	///< switch is on (custom value, used by Dimmer)
			STATE_OFF			= 0x04	///< switch is off
		 };

	public:
		/**
		 * @brief  Evaluate if the switch state is \c STATE_ON. Provided for convenience.
		 * @return true if the state is wosh::interfaces::devices::Switch::STATE_ON; false else
		 */
		inline bool isSwitchOn() const		{ return (getSwitchState() == STATE_ON); }
		/**
		 * @brief  Evaluate if the switch state is \c STATE_ONDIMMED. Provided for convenience.
		 * @return true if the state is wosh::interfaces::devices::Switch::STATE_ONDIMMED; false else
		 */
		inline bool isSwitchDimmed() const	{ return (getSwitchState() == STATE_ONDIMMED); }
		/**
		 * @brief  Evaluate if the switch state is \c STATE_OFF. Provided for convenience.
		 * @return true if the state is wosh::interfaces::devices::Switch::STATE_OFF; false else
		 */
		inline bool isSwitchOff() const		{ return (getSwitchState() == STATE_OFF); }
		/**
		 * @brief   Get switch state as a literal string
		 * @return C string represeting the current state
		 * @see    Switch::getSwitchStateAsString
		 */
		inline const char* getSwitchStateAsString() const { return getSwitchStateAsString(getSwitchState()); }

/** @name Switch Interface
 * @{
 ******************************************************************************/
	public:
		/**
		 * @brief  Evaluate switch's state. Implemented by inherited classes.
		 * @return the current state of the switch
		 */
		virtual SWITCH_STATE getSwitchState() const = 0;

//@}
	public:
		/**
		 * @brief   Get switch state as a literal string
		 * @param state [in] switch state to be retrieved as literal string
		 * @return  passed switch state as literal string
		 */
		static const char* getSwitchStateAsString( SWITCH_STATE state ) {
			switch(state) {
				case STATE_ON:				return "ON";
				case STATE_ONDIMMED:		return "ONDIMMED";
				case STATE_OFF:				return "OFF";
				case STATE_UNKNOWN:
				default:					return "UNKNOWN";
			 }
		 }
		/**
		 * @brief   Get switch state from a literal string
		 * @param state [in] switch state as literal string
		 * @return  switch state (as enum) associated with the argument 
		 */
		static SWITCH_STATE getSwitchStateFromString( const char* state ) {
			if ( state == NULL )							return STATE_UNKNOWN;
			else if ( strcmp(state, "ON") == 0 )			return STATE_ON;
			else if ( strcmp(state, "ONDIMMED") == 0 )		return STATE_ONDIMMED;
			else if ( strcmp(state, "OFF") == 0 )			return STATE_OFF;
			return STATE_UNKNOWN;
		 }

	public:
		virtual ~Switch() { }

}; // class def

  }; // namespace devices
 }; // namespace interfaces
}; // namespace wosh

#endif //__WOSH_Interfaces_Devices_Switch_H__
